import { msmReceiveMap, recordStatusMap, msmRecordMap } from '@/config/dict'
import { findDict } from '@/utils/index'

export const queryFormItem = [
  {
    type: 'date',
    key: 'beginDate',
    // label: '开始时间',
    otherAttrs: {
      style: {
        width: '140px'
      },
      placeholder: '开始日期'
    }
  },
  {
    type: 'date',
    key: 'endDate',
    // label: '结束时间',
    otherAttrs: {
      style: {
        width: '140px'
      },
      placeholder: '结束日期'
    }
  },
  {
    type: 'select',
    key: 'receiver',
    // label: '接收人',
    options: msmReceiveMap,
    otherAttrs: {
      style: {
        width: '110px'
      },
      placeholder: '接收人'
    }
  },
  {
    type: 'select',
    key: 'status',
    // label: '状态',
    options: recordStatusMap,
    otherAttrs: {
      style: {
        width: '110px'
      },
      placeholder: '状态'
    }
  },
  {
    type: 'input',
    key: 'keyword',
    // label: '请输入业务名称或标题关键字',
    otherAttrs: {
      style: {
        width: '200px'
      },
      placeholder: '请输入业务名称或标题关键字'
    }
  }
]
// 预警点的状态
const format = records => {
  return findDict(msmRecordMap, records.row.warningLevel)
}

// 字体颜色的状态
const formatStatus = records => {
  return findDict(recordStatusMap, records.row.status)
}

// 状态的文字
const formatStatusValue = statusId => {
  let statusValue = ''
  switch (statusId) {
    case 1:
      statusValue = '未完成'
      break
    case 2:
      statusValue = '部份完成'
      break
    case 3:
      statusValue = '已完成'
      break
    case 4:
      statusValue = '已关闭'
      break
    default:
      break
  }
  return statusValue
}
// 处理人数过多
// const filterNumPeople = value => {
//   var exportValue = ''
//   const result = value.split(',')
//   if (result.length >= 3) {
//     exportValue = `（共${result.length}人）${result.slice(0, 3).join('、')}...`
//   } else {
//     exportValue = result.join('、')
//   }
//   return exportValue
// }
export const tableColumn = (page, size, handleReceiver, handleSales) => {
  return [
    {
      key: 'businessName',
      label: '业务名称',
      minWidth: 200
    },
    {
      key: 'warningLevel',
      label: '预警级别',
      minWidth: 100,
      render: (h, scope) => (
        <span>
          <span
            style={
              'width:6px; height:6px; display: inline-block; border-radius: 50%;margin-right: 8px; background-color:' +
              format(scope).color
            }
          />
          <span>{scope.row.warningName}</span>
        </span>
      )
    },
    {
      key: 'content',
      label: '销项内容',
      minWidth: 360,
      render: (h, scope) => (
        <el-link onClick={() => handleSales(scope.row)}>
          {scope.row.content}
        </el-link>
      )
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 80,
      render: (h, scope) => (
        <span style={'color: ' + formatStatus(scope).color}>
          {formatStatusValue(scope.row.status)}
        </span>
      )
    },
    {
      key: 'receiverDesc',
      label: '接收人',
      minWidth: 220,
      render: (h, scope) => (
        <el-link onClick={() => handleReceiver(scope.row)}>
          {scope.row.receiverDesc}
        </el-link>
      )
    },
    {
      key: 'createTime',
      label: '发送时间',
      minWidth: 140
    }
  ]
}

// 处理状态的文字和状态显示
// 1=未完成 2=已完成 3=已取消
const formatStatusName = scope => {
  let name = ''
  let color = ''
  switch (scope.row.status) {
    case 1:
      name = '未完成'
      color = '#f00'
      break
    case 2:
      name = '已完成'
      break
    case 3:
      name = '已取消'
      break
    default:
      break
  }
  return { name, color }
}

// 接收人弹窗
export const receiverTableColumn = (page, size) => {
  return [
    // {
    //   key: 'N0',
    //   label: 'No',
    //   minWidth: 120
    // },
    // 姓名 状态 接收时间 完成时间
    // {
    //   key: 'deptName',
    //   label: '部门',
    //   minWidth: 120
    // },
    {
      key: 'userName',
      label: '姓名',
      minWidth: 120
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 120,
      render: (h, scope) => (
        <span style={'color: ' + formatStatusName(scope).color}>
          {formatStatusName(scope).name}
        </span>
      )
    },
    {
      key: 'receiveTime',
      label: '接收时间',
      minWidth: 120
    },
    {
      key: 'finishTime',
      label: '完成时间',
      minWidth: 120
    }
  ]
}
